package com.pf.utils;

import com.pf.dto.BaseResult;
import com.pf.enums.BaseResultEnums;

/**
 * @author PanFei
 * @date 2021/6/14 15:25
 * @Version 1.0
 */
public class BaseResultUtils {

    /**
     * 调用成功
     *
     * @param data
     * @param <T>
     * @return
     */
    public static <T> BaseResult<T> success(T data) {
        BaseResult result = new BaseResult<T>();
        result.setCode(BaseResultEnums.SUCCESS.getCode());
        result.setMsg(BaseResultEnums.SUCCESS.getMsg());
        result.setData(data);
        return result;
    }

    /**
     * 调用成功
     *
     * @return
     */
    public static BaseResult success() {
        return success(null);
    }

    /**
     * 调用失败
     *
     * @param code
     * @param msg
     * @return
     */
    public static BaseResult fail(Integer code, String msg) {
        BaseResult result = new BaseResult();
        result.setCode(code);
        result.setMsg(msg);
        result.setData(null);
        return result;
    }

    /**
     * 调用失败
     *
     * @param msg
     * @return
     */
    public static BaseResult fail(String msg) {
        return fail(BaseResultEnums.FAIL.getCode(), msg);
    }

    /**
     * 调用失败
     *
     * @return
     */
    public static BaseResult fail() {
        return fail(BaseResultEnums.FAIL.getMsg());
    }

    /**
     * 调用失败
     *
     * @param baseResultEnums
     * @return
     */
    public static BaseResult fail(BaseResultEnums baseResultEnums) {
        BaseResult result = new BaseResult();
        result.setCode(baseResultEnums.getCode());
        result.setMsg(baseResultEnums.getMsg());
        result.setData(null);
        return result;
    }
}
